package demo.using.redis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

/**
 * @author : GuoFei
 * @date : 2019/2/25 15:22
 */
public class RedisManager {
    // 通过Jedis连接池 来实例化
    private static JedisPool jedisPool;

    static {
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(18);
        jedisPoolConfig.setMaxIdle(8);
        jedisPool = new JedisPool(jedisPoolConfig, "127.0.0.1", 6379, 2000, "123123", 0);
    }

    public static Jedis getJedis(){
        if (null != jedisPool) {
            return jedisPool.getResource();
        }
        throw new RuntimeException("Jedispool was not init");

    }
}
